<script src='<?php echo DIR_JS?>ui.datepicker.js' type='text/javascript' language='javascript'> </script>
<div class="section" id="sitemaplist">
<form id="formlist" name="formlist" action="<?php echo $action?>" method="post" enctype="multipart/form-data" onSubmit="return false">
	<div class="section-title">
    	<?php echo $form_title?>
    </div>
    
    <div class="section-content padding1">
		<div>
			<p>
				<label><?php echo $this->document->text['text_debtchangebalance']?></label>
				 : <input type="text disable number" name="deptamount" value="<?php echo $voucher['deptamount']?>" class="text text-right deptamount" size="95" style="font-size:1.2em; font-weight:bold" readonly="" />
 			</p>
			<p>
				<label><?php echo $this->document->text['text_date']?></label> : <input type="text" id="voucherdate" name="voucherdate" class="text voucherdate" size="20" value="<?php echo $this->date->formatMySQLDate($voucher['voucherdate'],"DMY","-")?>" />
				<b><?php echo $this->document->text['text_vouchernol']?>:</b> : <input type="text" name="voucherno" class="text voucherno" size="20" value="<?php echo $voucher['voucherno']?>"  />
				<b><?php echo $this->document->text['text_cashier']?></b> : <select name="employeeid" style="width:300px"><?php echo $cb_cashier?></select>
			</p>
			<p>
				<label><?php echo $this->document->text['text_accounttype']?>:</label> : <select class="vouchergroupid" name="vouchergroup" style="width:830px"><?php echo $cb_vouchergroup?></select>
			</p>
			<p>
				<label><?php echo $this->document->text['text_payto']?>: </label>
				 : <select id="cbpartner" name="partnerid" style="width:600px"><?php echo $cb_partner?></select>
				<input type="button" class="quickadd button" value="Quick add" name="quickaddpartner" onclick="addpartner()" />
			</p>
			<div class="partnerinfor">
			<p>
				<label><?php echo $this->document->text['text_address']?></label> : <input type="text" name="address" class="text address" disabled="disabled" size="128" value="<?php echo $voucher['address']?>"  />
			</p>
			<p>
				<label><?php echo $this->document->text['text_tel']?>:</label> : <input type="text" name="address" class="text phone" disabled="disabled" size="20" value="<?php echo $voucher['phone']?>"  />
				<b><?php echo $this->document->text['text_fax']?></b> : <input type="text" name="fax" class="text fax" value="<?php echo $voucher['fax']?>" disabled="disabled" size="20"  />
				<b><?php echo $this->document->text['text_email']?></b> : <input type="text" name="email" class="text email" disabled="disabled" size="51" value="<?php echo $voucher['email']?>"  />
			</p>
			<p>
				<label><?php echo $this->document->text['text_bankaccount']?></label> : <input type="text" name="bankaccount" class="text bankaccount" disabled="disabled" size="50" value="<?php echo $voucher['bankaccount']?>"  />
				<b><?php echo $this->document->text['text_taxcode']?></b> : <input type="text" name="taxcode" class="text taxcode" disabled="disabled" size="53" value="<?php echo $voucher['taxcode']?>"  />
			</p>
			</div>
			<p>
				<label><?php echo $this->document->text['text_paymenttype']?>:</label> : <select name="paymenttype" style="width:300px"><?php echo $cb_paymenttype?></select>
				<b><?php echo $this->document->text['text_paymentamount']?>:</b> : <input type="text" name="totalpaid" class="text totalpaid" size="53" value="<?php echo $voucher['totalpaid']?>"  />
			</p>
			<p>
				<label><?php echo $this->document->text['text_description']?>:</label> : <textarea name="description" class="description" cols="125"><?php echo $voucher['description']?></textarea>
			</p>
			
		 </div>
    </div>
	
	<div class="section-title">
		<?php if($allowdelete) {?>
		<div class="button left">
			<input type="button" name="delete" value="<?php echo $this->document->text['button_delete']?>" class="button" onclick="deletevoucher()"/>
		</div> 
		<?php } ?>
        <div class="button right">
            <input type="button" name="save" value="<?php echo $this->document->text['button_save']?>" class="button" onclick="fsubmit(0)"/>
			<input type="button" name="saveprint" value="<?php echo $this->document->text['button_saveprint']?>" class="button" onclick="fsubmit(1)"/>
            <input type="button" value="<?php echo $this->document->text['button_cancel']?>" class="button" onclick="window.close()"/>   
            <input type="hidden" name="voucherid" value="<?php echo $voucher['voucherid']?>" /> 
			<input type="hidden" name="orderid" value="<?php echo $voucher['orderid']?>" />  
			<input type="hidden" class="vouchertype" name="vouchertype" value="<?php echo $voucher['vouchertype']?>" />   
			<input type="hidden" class="olddeptamount" name="olddeptamount" value="<?php echo $voucher['deptamount']?>" />
			<input type="hidden" class="print" name="print" value="" />   
        </div>
        <div class="clearer">^&nbsp;</div>
    </div>
</form>    
</div>
<script language="javascript">
 	$(function() {
		$("#voucherdate").datepicker({
				changeMonth: true,
				changeYear: true,
				dateFormat: 'dd-mm-yy'
				});
		if($("#cbpartner").val() == "")
		{
			_cbobject();
		}
		
		_partnerinfor();
		
	});
	
	$(document).ready(function(){
		$(".vouchergroupid").change(function(){
			_cbobject();
		});
		
		$(".vouchergroupid").change(function(){
			_cbobject();
		});
		
		$("#cbpartner").change(function(){
			_partnerinfor();
		});
		
		$(".totalpaid").keypress(function (e)
		{	
		  return isNumber(e.which);
		});
		
		$(".totalpaid").keyup(function(e){
			
			/*totalpaid = CDbl($(this).val().replace(/,/g,""));
			dept = 	CDbl($(".olddeptamount").val().replace(/,/g,""));		
			vouchertype = $(".vouchertype").val();
			if(vouchertype ==  "EXPENSE")
			{
				totalpaid = totalpaid*-1;
			}
			
			totaldept = dept - totalpaid;
						*/
			num = formateNumber($(this).val().replace(/,/g,""));
			
			$(this).val(num);
		});
		
		<?php if($_GET['print'] == '1' ) {?>
			var result = window.showModalDialog("index.php?route=voucher/report/voucher&voucherid=<?php echo $voucherid?>", "", "dialogWidth:750px; dialogHeight:600px; center:yes");
		<?php } ?>
		
	});
	
	function CDbl(number)
	{
		number = number.replace(",","");
		if((parseFloat(number)+"") == "NaN"){
			return 0;
		}
		else
		{
			return parseFloat(number);
		}
	}
		
	function _cbobject(){
		var vouchergroupid = $(".vouchergroupid").val();
		var url = "index.php?route=voucher/voucher/cbobject&groupid="+vouchergroupid;
		
		$.post(url, 
				$("#formlist").serialize(), 
				function(data)
				{
					$("#cbpartner").html(data);
					_partnerinfor();
				}
		);
	}
	
	function addpartner()
	{
		var vouchergroupid = $(".vouchergroupid").val();
		switch(vouchergroupid.substring(3,1))
		{
			case "S":
				var result = window.showModalDialog("index.php?route=category/supplier/quickadd", "", "dialogWidth:1000px; dialogHeight:600px; center:yes");
			break;
			case "C":
				var result = window.showModalDialog("index.php?route=category/customer/quickadd", "", "dialogWidth:1000px; dialogHeight:600px; center:yes");
			break;
			case "E":
				var result = window.showModalDialog("index.php?route=category/employee/quickadd", "", "dialogWidth:1000px; dialogHeight:600px; center:yes");
			break;
			default:
				if($(".vouchertype").val() == "EXPENSE")
				{
					var result = window.showModalDialog("index.php?route=category/supplier/quickadd", "", "dialogWidth:1000px; dialogHeight:600px; center:yes");
				}
				else
				{
					var result = window.showModalDialog("index.php?route=category/customer/quickadd", "", "dialogWidth:1000px; dialogHeight:600px; center:yes");
				}
			break;
		}
	}
	
	function _partnerinfor()
	{
		var partnerid = $("#cbpartner").val();

		var url = "index.php?route=voucher/voucher/partnerinfo&partnerid="+partnerid;
	
		$.post(url, 
				$("#formlist").serialize(), 
				function(data)
				{
					$(".partnerinfor").html(data);
					$(".deptamount").val(formateNumber($(".dept").val()));
					$(".olddeptamount").val($(".dept").val());
				}
		);
	}
	
	function fsubmit(p){
		if(p == 1)
		{
			$(".print").val("1");
		}
		else{
			$(".print").val("0");
		}
		$("#formlist").submit();
	}
	
	 <?php if($savecomplete == true) {?>
	 	alert("Save successfully");
	 <?php } ?>
	
	
	function deletevoucher()
	{
		$.post("?route=voucher/search/deletevoucher&voucherid=<?php echo $voucherid?>", 
				$("#formlist").serialize(), 
				function(data)
				{
					alert("Delete successfully!");
					window.close();
					
				}
		);
	}
	
	
 </script>
 
 
